var app = getApp(),
  a = app.requirejs("core"),
  s = app.requirejs("wxParse/wxParse");
  var running=false;
Page({

  /**
   * 页面的初始数据
   */
  data: {
  id:0,
  show:false,
    bomb:!0,
    shdz:!0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    a.setting();
    that.setData(options);
    that.getinfo();
  },
  getinfo:function(){
      var that=this;
    a.get('Integral/goodsinfo',{
        id:that.data.id,
      uid: app.getCache('userinfo').uid
      },function(t){
        if(t.code==0){
          if (t.info.content){
            s.wxParse("wxParseData", "html", t.info.content, that, "0");
          }
          if (t.info.rules) {
            s.wxParse("wxParseData2", "html", t.info.rules, that, "0");
          }
          if (t.info.content) {
            s.wxParse("wxParseData3", "html", t.info.content, that, "0");
          }
          that.setData({
            info:t.info,
            show: true
          })
        }else{
          a.alert(t.msg);
        }
      },!that.data.show);
  },
  caomfirm:function(){
    var that=this;
    var info=that.data.info;
    if(running){
      return;
    }
    if (info.user_integral < info.integral){
      a.alert('积分不足！');
      return;
    }
    var type_lxm = info.type_lxm;
    var new_data = { 'goods_id': info.id, 'uid': app.getCache('userinfo').uid,'type_lxm':type_lxm};
    if(type_lxm==0){
      new_data['receiver_mobile'] = info.address.phone;
      new_data['receiver_area'] = info.address.area;
      new_data['receiver_address'] = info.address.address;
      new_data['receiver_name'] = info.address.consigner;
      if (!new_data.receiver_mobile || !new_data.receiver_area || !new_data.receiver_address || !new_data.receiver_name){
        a.alert('请选择收货地址');
        return;
      }
    }
    running=true;
    a.post('Integral/createorder',new_data,function(t){
      running=false;
      if(t.code==0){
        that.setData({
          bomb: !0
        });
        a.success('兑换成功');
        that.getinfo();
      }else{
        a.alert(t.msg);
      }
    })
  },
  select_address:function(){
    a.jump('/yb_shop/pages/member/address/select');
  },
  duihuan: function () {
    this.setData({
      bomb: !1
    });
  },
  cancel: function () {
    this.setData({
      bomb: !0
    });
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var d = app.getCache("orderAddress");
    if (d) {
      this.setData({
        "info.address": d,
      })
    }
  },

  /**
* 下拉刷新
*/
  onPullDownRefresh: function () {
    this.getinfo();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }

})